package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpSellerProductSkuBo;
import com.erp.gather.domain.vo.ErpSellerProductSkuVo;
import com.erp.gather.service.IErpSellerProductSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
 *
 * @author erp
 * @date 2023-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerProductSku")
public class ErpSellerProductSkuController extends BaseController {

    private final IErpSellerProductSkuService iErpSellerProductSkuService;

    /**
     * 查询ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerProductSkuVo> list(ErpSellerProductSkuBo bo, PageQuery pageQuery) {
        return iErpSellerProductSkuService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerProductSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerProductSkuService.queryById(id));
    }

    /**
     * 新增ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerProductSkuBo bo) {
        return toAjax(iErpSellerProductSkuService.insertByBo(bo));
    }

    /**
     * 修改ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerProductSkuBo bo) {
        return toAjax(iErpSellerProductSkuService.updateByBo(bo));
    }

    /**
     * 删除ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     *
     * @param ids 主键串
     */
    @Log(title = "ERP个人商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerProductSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
